package com.intellagric.controller.module.ift_data_record;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.module.iftmonitor.DataRecordVo;
import com.intellagric.pojo.IftDataRecord;
import com.intellagric.service.iftmonitor.ift_data_record.DataRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/21
 * @DESC： 数据记录管理
 */
@Controller
public class DataRecordController {

    @Autowired
    private DataRecordService dataRecordService;

    /**
     * 添加数据记录信息
     * @Param dataRecord
     * @return ResponseMessage
     */
    @RequestMapping("/datarecord/add")
    @ResponseBody
    public ResponseMessage add(IftDataRecord dataRecord) {
        dataRecord.setId(UUID.randomUUID().toString().replaceAll("-",""));
        return dataRecordService.addDataRecord(dataRecord);
    }

    /**
     * 删除数据记录信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/datarecord/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return dataRecordService.deleteDataRecord(id);
    }
    
    /**
     * 修改数据记录信息
     * @Param 
     * @return ResponseMessage
     */
    @RequestMapping("/datarecord/edit")
    @ResponseBody
    public ResponseMessage edit(IftDataRecord dataRecord) {
        return dataRecordService.editDataRecord(dataRecord);
    }
    
    /**
     * 查询数据记录信息
     * @return IftDataRecord
     */
    @RequestMapping("/datarecord/{id}")
    @ResponseBody
    public IftDataRecord get(@PathVariable String id) {
        return dataRecordService.getDataRecordById(id);
    }
    
    /**
     * 查询数据记录信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/datarecord/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return dataRecordService.getDataRecordList();
    }

    /**
     * 查询数据记录信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/datarecord/query")
    @ResponseBody
    public LayuiDataGridResult getListByVo(DataRecordVo dataRecordVo) {
        return dataRecordService.getDataRecordListByVo(dataRecordVo);
    }

    /**
     * 分页查询数据记录信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/datarecord/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit) {
        return dataRecordService.getDataRecordPage(page,limit);
    }

    /**
     * 分页查询数据记录信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/datarecord/page/relation")
    @ResponseBody
    public LayuiDataGridResult getPageWithRelation(int page,int limit) {
        return dataRecordService.getDataRecordPageAndRelation(page,limit);
    }

    /**
     * 多条件分页查询数据记录信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/datarecord/page/relation/query")
    @ResponseBody
    public LayuiDataGridResult getPageWithRelationByVo(int page, int limit, DataRecordVo dataRecordVo) {
        return dataRecordService.getDataRecordPageAndRelationByVo(page,limit,dataRecordVo);
    }
}
